package com.baizhi.user.controller;


import com.baizhi.user.entity.AdminRole;
import com.baizhi.user.entity.GrantUserRole;
import com.baizhi.user.entity.ResultEntity;
import com.baizhi.user.service.IAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhenggang
 * @since 2022-02-24
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private IAdminRoleService ars;
    @PostMapping("/grantRidForUserId")
    public ResultEntity grantRidForUserId(@RequestBody GrantUserRole gur){
        System.out.println("接收到了数据:"+gur);
        //把数据插入到用户角色表里面
        for(Integer roleId : gur.getRoleIds()){
            AdminRole ar=new AdminRole();
            ar.setAdminId(gur.getUserId());
            ar.setRoleId(roleId);
            ars.save(ar);
        }
        return ResultEntity.ok("插入成功");
    }
}

